package com.github.thinwonton.spring.aop.proxy;

import com.github.thinwonton.spring.aop.service.UserService;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;

import java.lang.reflect.Method;

public class UserServiceAdvisorByStaticMethodMatcherPointcutAdvisor extends StaticMethodMatcherPointcutAdvisor {

    /**
     * 指定支持的类
     */
    private static final Class<?> SUPPORTED_CLASS = UserService.class;

    /**
     * 指定支持的方法
     */
    private static final String[] SUPPORTED_METHODS = new String[]{"getByName"};

    @Override
    public boolean matches(Method method, Class<?> targetClass) {
        if (SUPPORTED_CLASS.isAssignableFrom(targetClass)) {
            for (String supportedMethod : SUPPORTED_METHODS) {
                if (method.getName().equals(supportedMethod)) {
                    return true;
                }
            }
        }

        return false;
    }
}
